/*
 * @lc app=leetcode.cn id=335 lang=cpp
 *
 * [335] 路径交叉
 */
#include "include.h"
// @lc code=start
class Solution {
public:
    bool isSelfCrossing(vector<int>& distance) {
        // <x, <y_start, y_end> >
        std::map<int, map<int, int>> verticalLineseg;
        // <y, <x_start, x_end> >
        std::map<int, map<int, int>> horizontalLineseg;
        
        bool verticalMove = true;
        int currentX = 0;
        int currentY = 0;
        int endX = 0;
        int endY = 0;
        for (int i=0;i<distance.size();i++){
            switch (i % 4)
            {
            // map : default = less, increasing
            // [1, 2, 3]
            // lower_bound(2) = 2 // not less than 2
            // upper_bound(2) = 3 // greater than 2
            case 0:
                // up
                // currentY < endY
                endY = currentY + distance[i];
                // same direction
                auto iter = verticalLineseg.find(currentX);
                if (iter == verticalLineseg.end()){
                    std::map<int, int> newVertical;
                    newVertical.emplace(currentY, endY);
                    verticalLineseg.emplace(currentX, newVertical);
                } else{
                    auto prevLineSeg = iter->second.lower_bound(currentY);
                    // if 
                    auto nextLineSeg = iter->second.upper_bound(endY);

                    // iter->second.
                }

                // check cross
                currentY = endY;
                break;
            case 1:
                // left
                currentX -= distance[i];
                break;
            case 2:
                // down
                currentY -= distance[i];
                break;
            case 3:
                // right
                currentX += distance[i];
                break;
            
            default:
                break;
            }
        }
        // int verticalLinesegX;
        // int horizontalLinesegY;
        return false;
    }
};
// @lc code=end

